package com.zbkj.service.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.zbkj.dal.base.constants.*;
import com.zbkj.dal.base.enums.DuesStatusEnums;
import com.zbkj.dal.base.enums.FundTradeTypeEnums;
import com.zbkj.dal.base.enums.QuotaChangeType;
import com.zbkj.dal.common.exception.CrmebException;
import com.zbkj.dal.common.utils.*;
import com.zbkj.dal.dao.DuesOrderMapper;
import com.zbkj.dal.entity.bill.Bill;
import com.zbkj.dal.entity.order.DuesOrder;
import com.zbkj.dal.entity.order.UserDuesRecord;
import com.zbkj.dal.entity.user.User;
import com.zbkj.dal.entity.user.UserToken;
import com.zbkj.dal.entity.wechat.WechatPayInfo;
import com.zbkj.dal.pojo.request.CreateDuesOrderRequest;
import com.zbkj.dal.pojo.request.PageParamRequest;
import com.zbkj.dal.pojo.request.ba.QueryDuesOrderRequest;
import com.zbkj.dal.pojo.response.CreateDuesOrderResponse;
import com.zbkj.dal.pojo.response.DuesOrderDetailVO;
import com.zbkj.dal.pojo.response.ba.DuesOrderResponse;
import com.zbkj.dal.pojo.vo.*;
import com.zbkj.service.manager.QuotaManager;
import com.zbkj.service.model.vo.DuesOrderListVO;
import com.zbkj.service.service.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

@Service
@Slf4j
public class DuesOrderServiceImpl extends ServiceImpl<DuesOrderMapper, DuesOrder> implements DuesOrderService {

    @Autowired
    private UserService userService;
    @Autowired
    private UserTokenService userTokenService;
    @Autowired
    private SystemConfigService systemConfigService;
    @Autowired
    private WechatService wechatService;
    @Autowired
    private TransactionTemplate transactionTemplate;
    @Autowired
    private UserDuesRecordService userDuesRecordService;
    @Autowired
    private BillService billService;
    @Autowired
    private WechatPayInfoService wechatPayInfoService;
    @Resource
    private RedisUtil redisUtil;
    @Resource
    private QuotaManager quotaManager;

    @Value("${image.default.quota.recharge}")
    private String defaultQuotaRechargeImage;

    /**
     * @param request
     * @return
     */
    @Override
    public CreateDuesOrderResponse createDuesOrder(CreateDuesOrderRequest request) {
        if (ObjectUtil.isNull(request.getPrice())) {
            throw new CrmebException("充值金额不能为空");
        }
        // 最小充值金额
        BigDecimal minAmount = BigDecimal.ZERO;
        if (request.getPrice().compareTo(minAmount) < 0) {
            throw new CrmebException("充值金额小于0");
        }

        User user = userService.getInfo();
        minAmount = new BigDecimal("9999.00");
        if (user.getLastDuesTime() == null && request.getPrice().compareTo(minAmount) < 0) {
            throw new CrmebException("首次充值金额不能小于9999");
        }

        String duesOrderNo = CrmebUtil.getOrderNo(OrderConstants.DUES_ORDER_PREFIX);
        CreateDuesOrderResponse response = new CreateDuesOrderResponse();
        DuesOrder duesOrder = new DuesOrder();
        duesOrder.setUid(user.getId());
        duesOrder.setOrderNo(duesOrderNo);
        duesOrder.setPrice(request.getPrice());
        duesOrder.setPaid(DuesStatusEnums.UNPAID.getCode());
        boolean save = save(duesOrder);
        if (!save) {
            throw new CrmebException("生成会费充值订单失败!");
        }
        response.setOrderNo(duesOrderNo);
        // 加入自动未支付自动取消队列
        redisUtil.lPush(TaskConstants.QUOTA_RECHARGE_TASK_REDIS_KEY_AUTO_CANCEL_KEY, duesOrderNo);

        // 查询
        return response;
    }

    @Override
    public DuesOrder getByOrderNo(String orderNo) {
        if (StringUtils.isBlank(orderNo)) {
            throw new CrmebException("订单号不能为空！");
        }
        LambdaQueryWrapper<DuesOrder> queryWrapper = Wrappers.lambdaQuery(DuesOrder.class);
        queryWrapper.eq(DuesOrder::getOrderNo, orderNo);
        return this.getOne(queryWrapper);
    }

    @Override
    public DuesOrder getDuesOrderByOutTradeNo(String outTradeNo) {
        LambdaQueryWrapper<DuesOrder> queryWrapper = Wrappers.lambdaQuery(DuesOrder.class);
        queryWrapper.eq(DuesOrder::getOutTradeNo, outTradeNo);
        return this.getOne(queryWrapper);
    }

    @Override
    public Boolean paySuccessAfter(DuesOrder duesOrder, WechatPayInfo wechatPayInfo) {
        User user = userService.getById(duesOrder.getUid());

        BigDecimal addPrice = duesOrder.getPrice();
        BigDecimal balance = user.getDuesAmount().add(addPrice);
        BigDecimal creditBalance = user.getCreditAmount().add(addPrice);

        user.setDuesAmount(balance);

        UserDuesRecord userDuesRecord = new UserDuesRecord();
        userDuesRecord.setUid(duesOrder.getUid());
        userDuesRecord.setLinkId(duesOrder.getOrderNo());
        userDuesRecord.setLinkType(BalanceRecordConstants.BALANCE_RECORD_LINK_TYPE_DUES);
        userDuesRecord.setType(BalanceRecordConstants.BALANCE_RECORD_TYPE_ADD);
        userDuesRecord.setAmount(addPrice);
        userDuesRecord.setBalance(balance);

        userDuesRecord.setCreditAmount(addPrice);
        userDuesRecord.setCreditBalance(creditBalance);

        userDuesRecord.setRemark(StrUtil.format(BalanceRecordConstants.BALANCE_RECORD_REMARK_RECHARGE, addPrice));

        Bill bill = new Bill();
        bill.setOrderNo(duesOrder.getOrderNo());
        bill.setUid(duesOrder.getUid());
        bill.setPm(BillConstants.BILL_PM_ADD);
        bill.setAmount(duesOrder.getPrice());
        bill.setType(BillConstants.BILL_TYPE_DUES_USER);
        bill.setMark(StrUtil.format("会员会费充值，用户充值金额{}元", duesOrder.getPrice()));

//      1.更新订单支付状态，支付时间
//      2.更新会员总会费值
//      3.是否需要升级
//      4.保存充值流水
        Boolean execute = transactionTemplate.execute(p -> {
            updateDuesOrderPaid(duesOrder);

            quotaManager.addQuota(user.getId(), duesOrder.getPrice(), duesOrder.getOrderNo(), QuotaChangeType.QUOTA_RECHARGE.getCode(), defaultQuotaRechargeImage, QuotaChangeType.QUOTA_RECHARGE.getDesc());

            userDuesRecordService.save(userDuesRecord);

            billService.save(bill);

            if (wechatPayInfo != null) {
                wechatPayInfoService.updateById(wechatPayInfo);
            }

            return Boolean.TRUE;
        });

//        if (execute) {
//            // 首充可获得佣金
//            if (user.getLastDuesTime() == null) {
//                SettleStrategy settleStrategy = settlementFactory.create(SettlementConstants.UPGRADE);
//                List<UserBrokerageRecord> userBrokerageRecords = settleStrategy.execute(duesOrder.getOrderNo());
//                if (CollectionUtils.isNotEmpty(userBrokerageRecords)) {
//                    userBrokerageRecordService.saveBatch(userBrokerageRecords);
//                }
//                merchantService.extractAndSaveBrokerage(userBrokerageRecords);
//            }
//        }

        return execute;
    }

    @Override
    public List<DuesOrderListVO> listMyDuesOrder(Integer status, PageParamRequest pageRequest) {
        if (pageRequest.getLimit() <= 0) {
            pageRequest.setLimit(Constants.DEFAULT_LIMIT);
        }
        if (pageRequest.getLimit() > 100) {
            pageRequest.setLimit(Constants.DEFAULT_LIMIT);
        }

        User info = userService.getInfo();
        LambdaQueryWrapper<DuesOrder> queryWrapper = Wrappers.lambdaQuery(DuesOrder.class);
        queryWrapper.eq(DuesOrder::getUid, info.getId());
        queryWrapper.eq(Objects.nonNull(status) && status >= 0, DuesOrder::getPaid, status);
        queryWrapper.orderByDesc(DuesOrder::getId);
        queryWrapper.last(" LIMIT " + (pageRequest.getPage() - 1) * pageRequest.getLimit() + "," + pageRequest.getLimit());
        List<DuesOrder> list = this.list(queryWrapper);
        return list.stream().map(order -> {
            DuesOrderListVO duesOrderListVO = new DuesOrderListVO();
            duesOrderListVO.setUid(order.getUid());
            duesOrderListVO.setOrderNo(order.getOrderNo());
            duesOrderListVO.setPrice(order.getPrice());
            duesOrderListVO.setPayType(order.getPayType());
            duesOrderListVO.setPayChannel(order.getPayChannel());
            duesOrderListVO.setPaid(order.getPaid());
            duesOrderListVO.setPayTime(order.getPayTime());
            duesOrderListVO.setOutTradeNo(order.getOutTradeNo());
            duesOrderListVO.setCreateTime(order.getCreateTime());
            duesOrderListVO.setUpdateTime(order.getUpdateTime());
            duesOrderListVO.setImageUrl(FundTradeTypeEnums.QUOTA_RECHARGE.getDefaultImg());
            return duesOrderListVO;
        }).collect(Collectors.toList());
    }

    @Override
    public Boolean deleteMyOrder(String orderNo) {
        if (StringUtils.isBlank(orderNo)) {
            throw new CrmebException("订单号不能为空");
        }
        Integer userId = userService.getUserIdException();
        LambdaQueryWrapper<DuesOrder> queryWrapper = Wrappers.lambdaQuery(DuesOrder.class);
        queryWrapper.eq(DuesOrder::getOrderNo, orderNo).eq(DuesOrder::getUid, userId).ne(DuesOrder::getPaid, DuesStatusEnums.PAID.getCode());
        return this.remove(queryWrapper);
    }

    @Override
    public PageInfo<DuesOrderResponse> pageDuesOrders(QueryDuesOrderRequest duesOrderRequest, PageParamRequest pageRequest) {
        LambdaQueryWrapper<DuesOrder> queryWrapper = Wrappers.lambdaQuery(DuesOrder.class);
        if (StringUtils.isNotBlank(duesOrderRequest.getOrderNo())) {
            queryWrapper.eq(DuesOrder::getOrderNo, duesOrderRequest.getOrderNo());
        }
        if (StringUtils.isNotBlank(duesOrderRequest.getDateLimit())) {
            buildRequestTimeWhere(queryWrapper, duesOrderRequest.getDateLimit());
        }
        queryWrapper.orderByDesc(DuesOrder::getId);
        List<DuesOrder> list = this.list(queryWrapper);
        PageInfo<DuesOrder> pageInfo = PageInfo.of(list);
        List<Integer> userIds = list.stream().filter(p -> p.getUid() != null).map(m -> m.getUid()).distinct().collect(Collectors.toList());
        Map<Integer, User> uidMapList = Maps.newHashMap();
        if (CollectionUtils.isNotEmpty(userIds)) {
            uidMapList = userService.getUidMapList(userIds);
        }
        Map<Integer, User> finalUidMapList = uidMapList;
        PageInfo<DuesOrderResponse> result = PageInfoUtil.convert(pageInfo, entity -> {
            DuesOrderResponse duesOrderResponse = new DuesOrderResponse();
            BeanUtils.copyProperties(entity, duesOrderResponse);
            User user = finalUidMapList.get(duesOrderResponse.getUid());
            if (user != null) {
                duesOrderResponse.setNickName(user.getNickname());
            }
            return duesOrderResponse;
        });

        return result;
    }

    @Override
    public List<DuesOrderResponse> duesOrders(QueryDuesOrderRequest duesOrderRequest) {
        LambdaQueryWrapper<DuesOrder> queryWrapper = Wrappers.lambdaQuery(DuesOrder.class);
        if (StringUtils.isNotBlank(duesOrderRequest.getOrderNo())) {
            queryWrapper.eq(DuesOrder::getOrderNo, duesOrderRequest.getOrderNo());
        }
        if (StringUtils.isNotBlank(duesOrderRequest.getDateLimit())) {
            buildRequestTimeWhere(queryWrapper, duesOrderRequest.getDateLimit());
        }
        List<DuesOrder> list = this.list(queryWrapper);

        List<Integer> userIds = list.stream().filter(p -> p.getUid() != null).map(m -> m.getUid()).distinct().collect(Collectors.toList());
        Map<Integer, User> uidMapList = userService.getUidMapList(userIds);

        List<DuesOrderResponse> duesOrderResponses = Lists.newArrayList();
        for (DuesOrder duesOrder : list) {
            DuesOrderResponse duesOrderResponse = new DuesOrderResponse();
            BeanUtils.copyProperties(duesOrder, duesOrderResponse);
            User user = uidMapList.get(duesOrderResponse.getUid());
            if (user != null) {
                duesOrderResponse.setNickName(user.getNickname());
            }
            duesOrderResponses.add(duesOrderResponse);
        }

        return duesOrderResponses;
    }

    /**
     * 获取request的where条件
     *
     * @param lqw       LambdaQueryWrapper<Order> 表达式
     * @param dateLimit 时间区间参数
     */
    private void buildRequestTimeWhere(LambdaQueryWrapper<DuesOrder> lqw, String dateLimit) {
        DateLimitUtilVo dateLimitUtilVo = CrmebDateUtil.getDateLimit(dateLimit);
        lqw.between(DuesOrder::getCreateTime, dateLimitUtilVo.getStartTime(), dateLimitUtilVo.getEndTime());
    }

    /**
     * 更新会费充值支付状态
     *
     * @param duesOrder
     */
    private void updateDuesOrderPaid(DuesOrder duesOrder) {
        LambdaUpdateWrapper<DuesOrder> updateWrapper = Wrappers.lambdaUpdate(DuesOrder.class);

        updateWrapper.set(DuesOrder::getPaid, DuesStatusEnums.PAID.getCode()).set(DuesOrder::getPayTime, LocalDateTime.now())
                .eq(DuesOrder::getId, duesOrder.getId())
                .eq(DuesOrder::getOrderNo, duesOrder.getOrderNo())
                .eq(DuesOrder::getPaid, DuesStatusEnums.UNPAID.getCode());
        this.update(updateWrapper);
    }

    /**
     * 微信支付
     *
     * @param rechargePrice 充值金额
     * @param payChannel    支付渠道
     * @param uid           用户id
     * @return
     */
    private MyRecord wechatPayment(BigDecimal rechargePrice, String payChannel, Integer uid) {
        // 预下单
        Map<String, String> unifiedorder = wechatUnifiedorder(rechargePrice, payChannel, uid);
        WxPayJsResultVo vo = new WxPayJsResultVo();
        vo.setAppId(unifiedorder.get("appId"));
        vo.setNonceStr(unifiedorder.get("nonceStr"));
        vo.setPackages(unifiedorder.get("package"));
        vo.setSignType(unifiedorder.get("signType"));
        vo.setTimeStamp(unifiedorder.get("timeStamp"));
        vo.setPaySign(unifiedorder.get("paySign"));
        if (payChannel.equals(PayConstants.PAY_CHANNEL_H5)) {
            vo.setMwebUrl(unifiedorder.get("mweb_url"));
        }
        if (payChannel.equals(PayConstants.PAY_CHANNEL_WECHAT_APP_IOS) ||
                payChannel.equals(PayConstants.PAY_CHANNEL_WECHAT_APP_ANDROID)) {// App
            vo.setPartnerid(unifiedorder.get("partnerid"));
        }
        MyRecord record = new MyRecord();
        record.set("dto", vo);
        record.set("outTradeNo", unifiedorder.get("outTradeNo"));
        return record;
    }

    /**
     * 微信预下单
     *
     * @param rechargePrice 充值金额
     * @param payChannel    支付渠道
     * @return 预下单返回对象
     */
    private Map<String, String> wechatUnifiedorder(BigDecimal rechargePrice, String payChannel, Integer uid) {
        // 获取用户openId
        // 根据订单支付类型来判断获取公众号openId还是小程序openId
        UserToken userToken = new UserToken();
        userToken.setToken("");
        if (payChannel.equals(PayConstants.PAY_CHANNEL_WECHAT_PUBLIC)) {// 公众号
            userToken = userTokenService.getTokenByUserId(uid, UserConstants.USER_TOKEN_TYPE_WECHAT);
        }
        if (payChannel.equals(PayConstants.PAY_CHANNEL_WECHAT_MINI)) {// 小程序
            userToken = userTokenService.getTokenByUserId(uid, UserConstants.USER_TOKEN_TYPE_ROUTINE);
        }

        // 获取appid、mch_id、微信签名key
        String appId = "";
        String mchId = "";
        String signKey = "";
        switch (payChannel) {
            case PayConstants.PAY_CHANNEL_WECHAT_PUBLIC:
            case PayConstants.PAY_CHANNEL_H5:// H5使用公众号的信息
                appId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PUBLIC_APPID);
                mchId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_PUBLIC_MCHID);
                signKey = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_PUBLIC_KEY);
                break;
            case PayConstants.PAY_CHANNEL_WECHAT_MINI:
                appId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_MINI_APPID);
                mchId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_MINI_MCHID);
                signKey = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_MINI_KEY);
                break;
            case PayConstants.PAY_CHANNEL_WECHAT_APP_IOS:
            case PayConstants.PAY_CHANNEL_WECHAT_APP_ANDROID:
                appId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_APP_APPID);
                mchId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_APP_MCHID);
                signKey = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_APP_KEY);
                break;
        }
        // 获取微信预下单对象
        CreateOrderRequestVo unifiedorderVo = getUnifiedorderVo(rechargePrice, uid, userToken.getToken(), appId, mchId, signKey, payChannel);
        // 预下单
        CreateOrderResponseVo responseVo = wechatService.payUnifiedorder(unifiedorderVo);
        // 组装前端预下单参数
        Map<String, String> map = new HashMap<>();
        map.put("appId", unifiedorderVo.getAppid());
        map.put("nonceStr", responseVo.getNonceStr());
        map.put("package", "prepay_id=".concat(responseVo.getPrepayId()));
        map.put("signType", "RSA");
        Long currentTimestamp = WxPayUtil.getCurrentTimestamp();
        map.put("timeStamp", Long.toString(currentTimestamp));
//        String paySign = WxPayUtil.getSign(map, signKey);
        map.put("paySign", responseVo.getSign());
        map.put("prepayId", responseVo.getPrepayId());
        map.put("prepayTime", CrmebDateUtil.nowDateTimeStr());
        map.put("outTradeNo", unifiedorderVo.getOut_trade_no());
        if (payChannel.equals(PayConstants.PAY_CHANNEL_H5)) {
            map.put("mweb_url", responseVo.getMWebUrl());
        }
        if (payChannel.equals(PayConstants.PAY_CHANNEL_WECHAT_APP_IOS) ||
                payChannel.equals(PayConstants.PAY_CHANNEL_WECHAT_APP_ANDROID)) {// App
            map.put("partnerid", mchId);
            map.put("package", responseVo.getPrepayId());
            Map<String, Object> appMap = new HashMap<>();
            appMap.put("appid", unifiedorderVo.getAppid());
            appMap.put("partnerid", mchId);
            appMap.put("prepayid", responseVo.getPrepayId());
            appMap.put("package", "Sign=WXPay");
            appMap.put("noncestr", unifiedorderVo.getNonce_str());
            appMap.put("timestamp", currentTimestamp);
            log.info("================================================app支付签名，map = " + appMap);
            String sign = WxPayUtil.getSignObject(appMap, signKey);
            log.info("================================================app支付签名，sign = " + sign);
            map.put("paySign", sign);
        }
        return map;
    }

    /**
     * 获取微信预下单对象
     */
    private CreateOrderRequestVo getUnifiedorderVo(BigDecimal rechargePrice, Integer uid, String openid, String appId, String mchId, String signKey, String payChannel) {
        // 获取域名
        String domain = systemConfigService.getValueByKeyException(SysConfigConstants.CONFIG_KEY_SITE_URL);
        String apiDomain = systemConfigService.getValueByKeyException(SysConfigConstants.CONFIG_KEY_API_URL);

        AttachVo attachVo = new AttachVo(PayConstants.PAY_SERVICE_TYPE_DUES, uid);

        CreateOrderRequestVo vo = new CreateOrderRequestVo();
        vo.setAppid(appId);
        vo.setMch_id(mchId);
        vo.setNonce_str(WxPayUtil.getNonceStr());
        vo.setSign_type(PayConstants.WX_PAY_SIGN_TYPE_MD5);
        String siteName = systemConfigService.getValueByKeyException(SysConfigConstants.CONFIG_KEY_SITE_NAME);
        // 因商品名称在微信侧超长更换为网站名称
        vo.setBody(siteName);
        vo.setAttach(JSONObject.toJSONString(attachVo));
        vo.setOut_trade_no(CrmebUtil.getOrderNo(OrderConstants.ORDER_PREFIX_WECHAT));
        // 订单中使用的是BigDecimal,这里要转为Integer类型
        vo.setTotal_fee(rechargePrice.multiply(BigDecimal.TEN).multiply(BigDecimal.TEN).intValue());
        vo.setSpbill_create_ip(RequestUtil.getClientIp());
        vo.setNotify_url(apiDomain + PayConstants.WX_PAY_NOTIFY_API_URI);
        switch (payChannel) {
            case PayConstants.PAY_CHANNEL_H5:
                vo.setTrade_type(PayConstants.WX_PAY_TRADE_TYPE_H5);
                vo.setOpenid(null);
                break;
            case PayConstants.PAY_CHANNEL_WECHAT_APP_IOS:
            case PayConstants.PAY_CHANNEL_WECHAT_APP_ANDROID:
                vo.setTrade_type(PayConstants.WX_PAY_TRADE_TYPE_APP);
                vo.setOpenid(null);
                break;
            default:
                vo.setTrade_type(PayConstants.WX_PAY_TRADE_TYPE_JS);
                vo.setOpenid(openid);
        }
        CreateOrderH5SceneInfoVo createOrderH5SceneInfoVo = new CreateOrderH5SceneInfoVo(
                new CreateOrderH5SceneInfoDetailVo(
                        domain,
                        systemConfigService.getValueByKeyException(SysConfigConstants.CONFIG_KEY_SITE_NAME)
                )
        );
        vo.setScene_info(JSONObject.toJSONString(createOrderH5SceneInfoVo));
        String sign = WxPayUtil.getSign(vo, signKey);
        vo.setSign(sign);
        return vo;
    }

    @Override
    public DuesOrderDetailVO duesOrderDetail(String orderNo) {
        LambdaQueryWrapper<DuesOrder> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DuesOrder::getOrderNo, orderNo);
        DuesOrder duesOrder = baseMapper.selectOne(wrapper);
        if (Objects.isNull(duesOrder)) {
            return null;
        }
        DuesOrderDetailVO duesOrderDetailVO = new DuesOrderDetailVO();
        duesOrderDetailVO.setUid(duesOrder.getUid());
        duesOrderDetailVO.setOrderNo(duesOrder.getOrderNo());
        duesOrderDetailVO.setPrice(duesOrder.getPrice());
        duesOrderDetailVO.setPayType(duesOrder.getPayType());
        duesOrderDetailVO.setPayChannel(duesOrder.getPayChannel());
        duesOrderDetailVO.setPaid(duesOrder.getPaid());
        duesOrderDetailVO.setPayTime(duesOrder.getPayTime());
        duesOrderDetailVO.setCreateTime(duesOrder.getCreateTime());
        return duesOrderDetailVO;
    }
}
